package pkg

import (
	"log"
	"os"
	"path/filepath"
)

func ReadDir(path string, groupLen int) [][]string {

	pwd, _ := os.Getwd()
	group := [][]string{}

	filePathList, err := filepath.Glob(filepath.Join(pwd, path))

	if err != nil {
		log.Fatal(err)
	}

	filePathListLen := len(filePathList)

	groupItemLen := filePathListLen / groupLen
	groupLastItemLen := filePathListLen % groupLen

	if groupLastItemLen != 0 {
		group = append(group, filePathList[filePathListLen-groupLastItemLen:filePathListLen])
	}

	if groupItemLen != 0 {

		for i := 1; i <= groupItemLen; i++ {

			start := (i - 1) * groupLen
			end := i * groupLen
			group = append(group, filePathList[start:end])
		}

	}

	return group
}
